﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AO.Core;

namespace ZoneEngine.Functions
{
    class Function_teleport : FunctionPrototype
    {
        public new int FunctionNumber = 53016;
        
        public new string FunctionName = "teleport";
        
        public override int ReturnNumber()
        { 
            return FunctionNumber; 
        }
        
        public override bool Execute(Dynel Self, Dynel Caller, object Target, object[] Arguments)
        {
            lock (Self)
            {
                lock (Caller)
                {
                    lock (Target)
                    {
                        return FunctionExecute(Self, Caller, Target, Arguments);
                    }
                }
            }
        }
        
        public override string ReturnName()
        {
            return FunctionName;
        }

        public bool FunctionExecute(Dynel Self, Dynel Caller, object Target, object[] Arguments)
        {
            Client cli = ((Character)Self).client;
            Quaternion q = new Quaternion(0, 1, 0, 0);
            AOCoord a = new AOCoord();
            Int32 pf;
            if (Target is Statels.Statel)
            {
                a.x = Int32.Parse((string)Arguments[0]);
                a.y = Int32.Parse((string)Arguments[1]);
                a.z = Int32.Parse((string)Arguments[2]);
                pf = Int32.Parse((string)Arguments[3]);
            }
            else
            {
                a.x = (Int32)Arguments[0];
                a.y = (Int32)Arguments[1];
                a.z = (Int32)Arguments[2];
                pf = (Int32)Arguments[3];
            }
            cli.Teleport(a, q, pf);
            return true; 
        }
    }
}
